/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var subsetsWithDup = function(nums) {

    // 数组排序 找到相同的数字
    nums.sort((a, b) => {return a - b})
    // return nums

    // 返回最终的结果
    let result = []
    backtrack(0, [])
    return result

    function backtrack(index, track){
        result.push([...track])

        for (let i = index; i < nums.length; i++) {
            // 数字相同 跳出本次循环
            if ( i - 1 >= index && nums[i - 1] == nums[i])
                continue
            track.push(nums[i])
            backtrack(i + 1, track)
            track.pop()
        }

    }
}
let nums = [1,2,2]
console.log(subsetsWithDup(nums))